package com.localtime;

import org.junit.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeDemo {
    @Test
    public void now() {
        System.out.println(LocalDateTime.now());
        System.out.println(LocalDateTime.now(ZoneId.systemDefault()));
        System.out.println(LocalDate.now());
        System.out.println(LocalTime.now());
    }

    @Test
    public void of() {
        System.out.println(LocalDateTime.of(2012, 10, 10, 2, 1));
        System.out.println(LocalDateTime.of(LocalDate.now(), LocalTime.now()));
    }

    @Test
    public void toLocalDate() {
        System.out.println(LocalDateTime.now().toLocalDate());
    }

    @Test
    public void getYear() {
        System.out.println(LocalDateTime.now().getYear());
    }

    @Test
    public void getDayOfYear() {
        System.out.println(LocalDateTime.now().getDayOfWeek());
    }

    @Test
    public void toEpochSecond() {
        System.out.println(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8)));
    }

    @Test
    public void plus() {
        System.out.println(LocalDateTime.of(2012, 10, 10, 2, 1));
        System.out.println(LocalDateTime.of(2012, 10, 10, 2, 1).plusDays(2));
    }

    @Test
    public void parse() {
        String dateTimeStr = "2021-10-11 11:11:11";
        LocalDateTime localDateTime = LocalDateTime.parse(dateTimeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(localDateTime.getHour());
    }
}
